<template>
    <van-form @submit="onSubmit">
        <van-cell-group inset>
            <van-field v-model="username" name="username" label="+86" placeholder="请输入收手机号"
                :rules="[{ required: true, message: '请填写用户名' }]" />
        </van-cell-group>
        <van-field v-model="password" type="password" name="password" label="密码" placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]" />
        <van-checkbox v-model="checked">复选框</van-checkbox>
        <span>我已同意《小米商城用户信息》 《小米商城隐私政策》《小米账号用户协议》《小米账号隐私政策》 </span>
        <div style="margin: 16px;">
            <van-button round block type="primary" native-type="submit">
                获取验证码
            </van-button>

            <p>密码登录</p>
        </div>
    </van-form>
</template>

<script setup>
import { ref } from 'vue';
import { showToast } from 'vant';


const checked = ref(true);
import { loginApi } from '@/api/app';
import { useRouter } from 'vue-router';
const router =useRouter()
const username = ref('');
const password = ref('');
const onSubmit = (values) => {
    loginApi(username.value, password.value).then(res => {
        if (res.data.code == 0) {
            localStorage.setItem("token", res.data.data.token)
            localStorage.setItem("username", res.data.data.username)
            showToast('登录成功');
            router.push('/home/my')
        }
        else {
showToast('失败');
        }

    })
};

</script>

<style lang="scss" scoped></style>